#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

class Solution
{
public:
    int minimumDeleteSum(string s1, string s2)
    {
        int m = s1.size();
        int n = s2.size();
        int totalSum = 0;
        for (int i = 0; i < m; i++)
        {
            totalSum += s1[i];
        }
        for (int j = 0; j < n; j++)
        {
            totalSum += s2[j];
        }
        if (m == 0 || n == 0)
            return totalSum;

        vector<vector<int>> commonSum(m + 1, vector<int>(n + 1));
        int maxCommonSum = 0;
        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (s1[i - 1] == s2[j - 1])
                {
                    commonSum[i][j] = commonSum[i - 1][j - 1] + s1[i - 1];
                }
                else
                {
                    commonSum[i][j] = max(commonSum[i - 1][j], commonSum[i][j - 1]);
                }
                maxCommonSum = max(maxCommonSum, commonSum[i][j]);
            }
        }
        return totalSum - 2 * maxCommonSum;
    }
};